package com.db.sevent;

import java.io.IOException;

import javax.swing.JOptionPane;

import com.component.LogingFrame;
import com.data.Data;
import com.db.bean.User;
import com.db.service.GroupServer;
import com.db.service.UserServer;
import com.main.RunFrame;
import com.view.P1;

/**
* @author 作者:秋哲    E-mail:2810201146@qq.com:
* @version 创建时间：2020年5月22日 下午6:32:37
* @description: 
*/
public class UserEvent {
	//登录 
	public void login() {
		String username = LogingFrame.getInstance().userNmae.getText(); //"root";//
		String password = new String( LogingFrame.getInstance().passWord.getPassword() );
		if(Data.config.DBUG) {
			username = "qiuzhe";
			password = "qiuzhe";
		}
		User loginObj = new UserServer().login(username, password);
		if(loginObj == null) {
			JOptionPane jOptionPane = new JOptionPane();
			jOptionPane.showMessageDialog(null, "登录失败");
		}else {
//			new RunFrame();
			boolean equals = "cadre".equals(loginObj.getRole());
			boolean equals2 = "admin".equals(loginObj.getRole());
			
			if(  !(equals || equals2) ) {
				System.out.println(loginObj.getRole().toString());
				new JOptionPane().showMessageDialog(null, "认证失败");
				return;
			}
//			if(!"admin".equals(loginObj.getRole())) {
//				new JOptionPane().showMessageDialog(null, "认证失败");
//				return;
//			}
			RunFrame.instance.setVisible(true);
			LogingFrame.getInstance().setVisible(false);
			new GroupServer().initGroupList();
			GroupEvent groupEvent = new GroupEvent();//.initGroupList();
			groupEvent.initGroupList();
			new WorkEvent().getWorkList();
			new UserServer().getPresidentUserAll();
		}
	}
	//获取个人信息 
	public void getinformation() {
		
	}
	//修改密码 
	public void changePasswork() {
		int n = new UserServer().changePasswork("型密码");
	}
	//打开目录
	public void openExplorer() {
		String path;
		String t1 = (String) P1.instance.com01.getSelectedItem();
		String t2 = P1.instance.list01.getSelectedValue();
		path = System.getProperty("user.dir")+"\\data"+"\\" + t1 +"\\" + t2+"\\";
		try {
			Process exec = Runtime.getRuntime().exec("explorer.exe /open," + path);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
